﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using CastleOfTheDisillusioned.Location;

namespace CastleOfTheDisillusioned {
	class Enemy : Entity {
		public double Health = 100;

		public bool IsDead = false;

		public Direction Facing = Direction.Left;

		protected bool TouchDamage = true;

		public override void Update() {
			if (TouchDamage && Location_State.CurrentPlayer.CollidesWith(this)) {
				Location_State.CurrentPlayer.TakeDamage(1);

				double XDiff = Location_State.CurrentPlayer.X - this.X;
				Location_State.CurrentPlayer.Throw(Math.Sign(XDiff) * 3 / 16.0, -2 / 16.0);
			}
		}

		public virtual void TakeDamage(double Damage) {
			Health -= Damage;

			int count = Program.Random.Next(3, 5);
			for (int i = 0; i < count; i++) {
				Particle p = new Particle(X + 0.5, Y + 0.5, 0.3, Color.Red);
				p.HSpeed = Program.Random.NextDouble() - 0.5;
				p.VSpeed = Program.Random.NextDouble() - 0.5;
				p.Lifespan = 5;
				ParticleManager.Track(p);
			}

			TextParticle tp = new TextParticle(X + 0.5, Y - 0.5, ((int)Damage).ToString());
			tp.VSpeed = -0.1;
			tp.Lifespan = 60;
			ParticleManager.Track(tp);

			if (Health <= 0) {
				Destroy();
			}
		}

		public virtual void Destroy() {
			IsDead = true;
		}
	}
}
